package com.example.miscontactos.Entidades;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class RegistrarUserWebHandler extends DefaultHandler
{
	private RegistracionUserWeb usuarioWeb;
	private StringBuilder texto;
	private final String USER_ITEM = "user";
	private final String USER_NAME = "username";
	private final String PASS = "password";
	private final String DETAIL = "detail";
	private final String DESCRIPTION = "description";
	
	public RegistracionUserWeb getUserName()
	{
		return usuarioWeb;
	}
	
	@Override
	public void characters(char[] ch, int start, int length) throws SAXException
	{
		super.characters(ch, start, length);
		if (this.usuarioWeb != null)
			texto.append(ch, start, length);
	}
	
	 @Override 
	  public void startElement(String namespaceURI, String localName, String qName, Attributes atr) throws SAXException { 
	 
	    if(localName.equals(USER_ITEM)) 
	    { 	 
	    	usuarioWeb.setUser(atr.getValue(USER_NAME));
	    	usuarioWeb.SetPass(atr.getValue(PASS));
	    }
	    else
	    {
	    	if(localName.equals(DETAIL))
	    		if (atr.getValue(DESCRIPTION) != null)
	    			usuarioWeb.SetError(atr.getValue(DESCRIPTION));
	    		/*else
	    			usuarioWeb.SetError("");*/
	    }
	  } 
}
